#ifndef CHRZFILE_H_INCLUDED
#define CHRZFILE_H_INCLUDED

#include "BrresFile.h"
#include <vector>
using namespace std;


enum  CHRZKEYFRAMEFORMAT
{
    I4  = 1,
    I6  = 2,
    I12 = 3,
    L1  = 4,
    L4  = 6,
};

typedef struct
{
    UINT            unknown0;
    USHORT          framecount;
    USHORT          anidatacount;
    UINT            isloop;   //0 for disenable, 1 for enable
    UINT            unknown1;
}  ChrzHeader ;

typedef struct
{
    UINT            anameoffset;
    UINT            fmtcode;
}   ChrzBoneAniInfo;

typedef struct
{
    USHORT           keyframecount;
    USHORT           unknown0;
    float           framescale;
    float           step;
    float           base;
}   Interpolated4_6;


typedef struct
{
    USHORT          keyframecount;
    USHORT          unknown0;
    float          framescale;
}   Interpolated12;

typedef struct
{
    float           step;
    float           base;
}   Linear1;

typedef struct
{
    UCHAR           frameid;
    UCHAR           sandtan[3];
}   I4FrameData ;

typedef struct
{
    USHORT          frameid;
    USHORT          step;
    USHORT          tan;
}   I6FrameData ;

typedef struct
{
    float           frameid;
    float           val;
    float           tan;
}   I12FrameData;

typedef struct
{
    UINT            frameid;
    float           ftime;
    float           value;
    float           tan;
} ChrzKeyFrameData;

typedef struct
{
    UINT                        xkeycount;
    UINT                        ykeycount;
    UINT                        zkeycount;
    bool                        islinear;
    ChrzKeyFrameData*           xkeys;
    ChrzKeyFrameData*           ykeys;
    ChrzKeyFrameData*           zkeys;
} ChrzKeyFrameCollection;


typedef struct _tagchrznode
{
    char*                       bname;
    ChrzKeyFrameCollection      *scalekeys;
    ChrzKeyFrameCollection      *rotkeys;
    ChrzKeyFrameCollection      *transkeys;

}   ChrzNode;


typedef struct
{
    UINT                        framecount;
    UINT                        nodecount;
    vector<ChrzNode*>          aninodes;
}   ChrzFile;

typedef struct
{
    UINT                        dataoffset;
    CHRZKEYFRAMEFORMAT          format;
    bool                       isotropic;
    bool                       xfixed,yfixed,zfixed;
}  ChrzAniFmtInfo ;

bool        readchrz(char *chrz,ChrzFile  **r);
bool        readchrzfromfile(const char* filename,ChrzFile **r);
void        freechrz(ChrzFile  *r);
#endif // CHR0FILE_H_INCLUDED

